home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / c / amivogl-1.03.lzh / vogl / examples / poly.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-07-16  |  2.9 KB  |  190 lines

  1. #include <stdio.h>
  2.  
  3. #ifdef SGI
  4. #include "gl.h"
  5. #include "device.h"
  6. #include "hershey.h"
  7. #else
  8. #include "vogl.h"
  9. #include "vodevice.h"
  10. #endif
  11.  
  12. /*
  13.  *    An array of points for a polygon
  14.  */
  15. static Coord    parray[][3] = {
  16.     {-8.0, -8.0, 0.0},
  17.     {-5.0, -8.0, 0.0},
  18.     {-5.0, -5.0, 0.0},
  19.     {-8.0, -5.0, 0.0}
  20. };
  21.  
  22. /*
  23.  * drawpoly
  24.  *
  25.  *    draw some polygons
  26.  */
  27. void drawpoly(void)
  28. {
  29.     float    vec[3];
  30.     short    val;
  31.  
  32.     color(YELLOW);
  33.  
  34.     /*
  35.      * Draw a polygon using poly, parray is our array of
  36.      * points and 4 is the number of points in it.
  37.      */
  38.     poly(4L, parray);
  39.  
  40.     color(GREEN);
  41.  
  42.     /*
  43.      * Draw a 5 sided figure by using bgnpolygon, v3d, and endpolygon
  44.      */
  45.     polymode(PYM_LINE);
  46.     bgnpolygon();
  47.         vec[0] = 0.0;
  48.         vec[1] = 0.0;
  49.         vec[2] = 0.0;
  50.         v3f(vec);
  51.         vec[0] = 3.0;
  52.         vec[1] = 0.0;
  53.         vec[2] = 0.0;
  54.         v3f(vec);
  55.         vec[0] = 3.0;
  56.         vec[1] = 4.0;
  57.         vec[2] = 0.0;
  58.         v3f(vec);
  59.         vec[0] = -1.0;
  60.         vec[1] = 5.0;
  61.         vec[2] = 0.0;
  62.         v3f(vec);
  63.         vec[0] = -2.0;
  64.         vec[1] = 2.0;
  65.         vec[2] = 0.0;
  66.         v3f(vec);
  67.     endpolygon();
  68.  
  69.     color(MAGENTA);
  70.  
  71.     /*
  72.      * draw a sector representing a 1/4 circle
  73.      */
  74.     arc(1.5, -7.0, 3.0, 0, 900);
  75.  
  76.     move2(1.5, -7.0);
  77.     draw2(1.5, -4.0);
  78.  
  79.     move2(1.5, -7.0);
  80.     draw2(4.5, -7.0);
  81.  
  82.     qread(&val);
  83. }
  84.  
  85. /*
  86.  * drawpolyf
  87.  *
  88.  *    draw some filled polygons
  89.  */
  90. void drawpolyf(void)
  91. {
  92.     short    val;
  93.  
  94.     color(YELLOW);
  95.  
  96.     polymode(PYM_FILL);
  97.  
  98.     /*
  99.      * Draw a polygon using poly, parray is our array of
  100.      * points and 4 is the number of points in it.
  101.      */
  102.     polf(4L, parray);
  103.  
  104.     color(GREEN);
  105.  
  106.     /*
  107.      * Draw a filled 5 sided figure by using pmv, pdr and pclos.
  108.      */
  109.     pmv(0.0, 0.0, 0.0);
  110.         pdr(3.0, 0.0, 0.0);
  111.         pdr(3.0, 4.0, 0.0);
  112.         pdr(-1.0, 5.0, 0.0);
  113.         pdr(-2.0, 2.0, 0.0);
  114.     pclos();
  115.  
  116.     color(MAGENTA);
  117.  
  118.     /*
  119.      * draw a filled sector representing a 1/4 circle
  120.      */
  121.     arcf(1.5, -7.0, 3.0, 0, 900);
  122.  
  123.     qread(&val);
  124. }
  125.  
  126. /*
  127.  * Using polygons, hatching, and filling.
  128.  */
  129. int main(void)
  130. {
  131.     short    val;
  132.  
  133.     winopen("poly");
  134.  
  135.     unqdevice(INPUTCHANGE);
  136.     qdevice(KEYBD);        /* enable keyboard */
  137.  
  138.     color(BLACK);        /* clear to black */
  139.     clear();
  140.  
  141.     /*
  142.      * world coordinates are now in the range -10 to 10
  143.      * in x, y, and z. Note that positive z is towards us.
  144.      */
  145.     ortho(-10.0, 10.0, -10.0, 10.0, 10.0, -10.0);
  146.  
  147.     color(YELLOW);
  148.  
  149.     /*
  150.      * write out the string "Polygon from poly()" in the
  151.      * starting at (-8.0, -4.0) and scaled to be 4.0 units long,
  152.      * 0.5 units high.
  153.      */
  154.     hfont("futura.m");
  155.     hboxtext(-8.0, -4.0, 4.0, 0.5, "Polygon from poly()/ polf()");
  156.  
  157.     color(GREEN);
  158.  
  159.     /*
  160.      * write out a scaled string starting at (0.0, 6.0)
  161.      */
  162.     hboxtext(0.0, 6.0, 4.5, 0.5, "Polygon from bgnpoly()/ endpoly()");
  163.     hboxtext(0.0, 5.0, 4.5, 0.5, "             pmv()/ pdr()/ pclos()");
  164.  
  165.     color(MAGENTA);
  166.  
  167.     /*
  168.      * write out a scaled string starting at (0.0, 6.0)
  169.      */
  170.     hboxtext(3.5, -3.5, 1.9, 0.5, "Arc/ Arcf");
  171.  
  172.     /*
  173.      * draw some wire frame polygons
  174.      */
  175.     drawpoly();
  176.  
  177.     /*
  178.      *  rotate so the next polygons will appear in a different place.
  179.      */
  180.     rot(20.0, 'x');
  181.     rot(30.0, 'y');
  182.  
  183.     /*
  184.      * draw some filled polygons.
  185.      */
  186.     drawpolyf();
  187.  
  188.     gexit();
  189. }
  190.